#include <head.h>

int main(int argc, char const *argv[])
{
    //
    int sock = socket( AF_INET , SOCK_STREAM ,0);
    if (-1 == sock)
    {
        ERRLOG("创建套接字失败");
        exit(-1);
    }
    
    //填写信息结构体
    struct sockaddr_in server_addr;
    //
    memset(&server_addr , 0 ,sizeof(server_addr));
    //
    server_addr.sin_family = AF_INET;
    //
    server_addr.sin_port = htons(7878);
    //
    server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
    

    if (-1 == bind(sock , (struct sockaddr *)&server_addr ,sizeof(server_addr)))
    {
        ERRLOG("绑定出错");
        close(sock);
        exit(-1);
    }
    
    printf("开始监听\n");

    if (-1 == listen(sock ,1))
    {
        ERRLOG("监听失败");
        close(sock);
        exit(-1);
    }
    
    int sock_client = accept(sock , NULL ,NULL);
    printf("连接成功\n");
    
    send(sock_client , "123456\n",strlen("123456\n"), 0 );
    
    close(sock);
    close(sock_client);
    return 0;
}